package com.xing.statistics.schedule;


import com.xing.statistics.service.DailyService;
import com.xing.statistics.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Scheduled:定时 Task：任务
 */
@Component
public class ScheduledTask {


    @Autowired
    private DailyService dailyService;

    //（0/5 * * * * ？）：每隔5秒执行一次
    @Scheduled(cron = "0/5 * * * * ?") //指定七子表达式corn表达式，定时任务，可以在线生成的
    public void task01(){
        System.out.println("====我执行啦");
    }

    //每天凌晨一点执行方法，把前一天的数据查询进行添加
    @Scheduled(cron= "0 0 1 * * ?")
    public void task02(){
        dailyService.createStatisticByDay(DateUtil.formatDate(DateUtil.addDays(new Date(),-1)));
    }

}
